<template>
	<view class="bookListBox">
		<bookList :bookInfo="bookLists"></bookList>
		<uni-load-more :status="loadStatus"></uni-load-more>
	</view>
</template>

<script>
	import bookList from '../../../components/bookList.vue'
	import key from '@/common/key.js';
	import utils from '@/common/utils.js';
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"

	export default {
		data() {
			return {
				bookLists: [],
				page: 1,
				lanmu_id: 0,
				loadStatus: 'loading',
				last_page: 0
			}
		},
		onLoad(opt) {
			
			this.lanmu_id = opt.lanmu_id
			this.getBookList(opt.lanmu_id, this.page)
		},
		onReachBottom() {

			if (this.page < this.last_page + 1) {
				this.getBookList(this.lanmu_id, this.page)
			} else {
				this.loadStatus = 'noMore'
			}

		},
		components: {
			bookList,
			uniLoadMore
		},
		methods: {
			// 请求数据
			getBookList(lanmu_id, page) {
				const data = {
					"app": "YLXS_Android",
					"channel": "H5",
					"device_id": 0,
					"t_channel": "YLXS_Android",
					"version": "1.0.0",
					"lanmu_id": lanmu_id,
					"page": page
				}

				let sign = utils.sortObj(data)
				uni.request({
					url: `${key.URL}a2/lanmu/detail`,
					method: 'POST',
					data: {
						"app": "YLXS_Android",
						"channel": "H5",
						"device_id": 0,
						"t_channel": "YLXS_Android",
						"version": "1.0.0",
						"lanmu_id": lanmu_id,
						"page": page,
						"sign": sign,
					},
					dataType: 'json',
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					success: (res) => {
						if (res.data.status == 200) {
							console.log(res);
							let data = res.data.data.data
							this.last_page = res.data.data.last_page
							data.forEach((val, index, arr) => {
								arr[index].img = utils.imgMd5(arr[index].img)
							})

							if (this.page <= res.data.data.last_page) {
								this.bookLists.push(data)
								this.page++
							}
						}
					}
				})
			},
		}
	}
</script>

<style>
	.bookListBox {
		padding: 30upx 0;
	}
</style>
